#!/usr/bin/php
<?php

 /* Jabberish - a multi-functional jabber bot
  * Copyright (C) 2006 Mark Walling <markwalling@gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */

error_reporting(E_ALL ^ E_NOTICE);

require("cjphp/class.jabber.php");
require("functions.inc.php");
//require("XML/RSS.php");

//prase_config_file();

$j = new Jabber;

$j->server = 'markwalling.dyndns.org'; //$config['server']['address'];
$j->port = '5222'; //$config['server']['port'];
$j->username = 'phpbot'; //$config['bot']['name'];
$j->password = 'apple'; //$config['bot']['password'];
$j->resource = 'Jabberish';
$j->enable_logging = true; //$config['log']['enabled'];
$j->log_filename = 'log/'.date("Y-m-d-H-i-s").'.botlog'; //$config['log']['filename'];

$bot_master = "mark@markwalling.dyndns.org";

$j->Connect() or die("Connect failed on line ".__LINE__);

$j->SendAuth() or die("SendAuth failed on line ".__LINE__);

$j->SendPresence() or die("SendPresence failed on line ".__LINE__);

$j->RosterUpdate() or die("RosterUpdate failed on line ".__LINE__);

//$j->SendMessage($config['bot']['master'], 'chat', null, array('body' => "This is a message"));
$j->SendMessage('mark@markwalling.dyndns.org', 'chat', null, array("body" => $j->resource." is online and ready"));

$j->CruiseControl();

$j->Disconnect();

function Handler_message_normal($message) {
	global $j;

	$from = $j->GetInfoFromMessageFrom($message);
	$body = $j->GetInfoFromMessageBody($message);

	$plain_body = trim(strtolower($body));
	if($plain_body == "about") {
		botaction_about_text($message);
	}
	elseif($plain_body == "warranty") {
		botaction_warranty_text($message);
	}
	elseif($plain_body == "conditions") {
		botaction_conditions_text($message);
	}
	/*elseif(preg_match("/weather/i", $plain_body)) {
		botaction_weather($message);
	}*/
	elseif(preg_match("/hello/i", $plain_body) || preg_match("/hi/i", $plain_body)) {
		botaction_welcome($message);
	}
	elseif($plain_body == "shutdown" || $plain_body == "quit") {
		botaction_quit($message);
	}

	else {
		$j->SendMessage($from, 'chat', null, array('body' => str_shuffle(trim($body)))) or die("SendMessage failed on line ".__LINE__);
	}
}

function Handler_message_chat($message) {
	Handler_message_normal($message);
}

?>

